<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   
	   $model = $this->getModel();
       $aut = new bgAuthorize();
       
       $task = JRequest::getVar('task');
       switch($task){
        
            case 'error':
                $this->row = (object)JRequest::getVar('jform');
                $this->action = JRequest::getVar('action');
                
                if(isset($_POST['cb1'])){
                    $this->row->OCBA_PUTF = 1;
                }
                if(isset($_POST['cb2'])){
                    $this->row->OCBA_LARF = 1;
                }
                if(isset($_POST['cb3'])){
                    $this->row->OCBA_CANF = 1;
                }
                if(isset($_POST['cb4'])){
                    $this->row->OCBA_YACF = 1;
                }
                if(isset($_POST['cb5'])){
                    $this->row->OCBA_SCHF = 1;
                }
                if(isset($_POST['cb6'])){
                    $this->row->OCBA_OUTF = 1;
                }
                if(isset($_POST['cbshow_hide'])){
                    $this->row->OCBA_FLAG = 1;
                }
                if(!empty($_FILES['jformOCBA_IMG']['name'])){
                    $this->row->OCBA_IMG = $_FILES['jformOCBA_IMG']['name'];
                }else{
                    if(!empty($_POST['jformOCBA_IMG_OLD'])){
                        $this->row->OCBA_IMG = $_POST['jformOCBA_IMG_OLD'];
                    }
                }
                $this->row->OCBA_LOAIHINH = $this->row->OCBA_loaihinh_CODE;
                                
                //check center or club
                if(substr($this->row->OCBA_CODE,0,1)=="1"){
                    $this->is_Club=true;
                }elseif(substr($this->row->OCBA_CODE,0,1)=="0"){
                    $this->is_Club=false;
                }else{
                    if($this->row->rd_centerclub == 1){
                        $this->is_Club=false;
                    }else{
                        $this->is_Club=true;
                    }
                }
                
                //Get DM Classification
                $master = new bgData();
                $this->listdm = $master->getDMClassification();
                //Get Activity
                $this->listacti = $master->getActivity();
                //Get list Coma
                $this->listcoma =& $model->getAllComa();
                
                $this->setLayout('a00610');
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
               	JToolBarHelper::cancel('cancel', 'キャンセル');
                JToolBarHelper::title( 'センター・クラブ情報作成','banners-tracks.png' );
                
                break;
            
            case 'edit':
                $cid = JRequest::getVar('cid');
                $cid = is_array($cid) ? $cid[0] : $cid;
                if($cid){
                    $this->row = $model->load($cid);
                }else{
                    //die('Not found');
                    die("データは見つかりませんでした");
                }
                //check center or club
                if(substr($cid,0,1)=="1"){
                    $this->is_Club=true;
                }else{
                    $this->is_Club=false;
                }
                /*if($model->isClub($cid)){
                    $this->is_Club=true;
                }else{
                    $this->is_Club=false;
                }*/
                //Get DM Classification
                $master = new bgData();
                $this->listdm = $master->getDMClassification();
                //Get Activity
                $this->listacti = $master->getActivity();
                //Get list Coma
                $this->listcoma =& $model->getAllComa();
                
                $this->setLayout('a00620');
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
               	JToolBarHelper::cancel('cancel', 'キャンセル');
                JToolBarHelper::title( 'センター・クラブ情報編集','banners-tracks.png' );
                
                break;
            case 'add':
                                
                //Get DM Classification
                $master = new bgData();
                $this->listdm = $master->getDMClassification();
                //Get Activity
                $this->listacti = $master->getActivity();
                //Get list Coma
                $this->listcoma =& $model->getAllComa();
                
                $this->setLayout('a00610');
                
                JToolBarHelper::title( 'センター・クラブ情報作成','banners-tracks.png' );
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','登録');
               	JToolBarHelper::cancel('cancel', 'キャンセル');
            break;
            
            case 'popup_term':
                
                $this->list_term =& $model->getAllTerm();  
                //$this->pagination =& $this->get('PaginationTerm');
                               
                $this->setLayout('popup_term');
            break;
            case 'popup_town':
                // Get data from the model
                $this->list_town =& $model->getAllListTown();  
                //$this->pagination =& $this->get('PaginationTown');
                               
                $this->setLayout('popup_town');
            break;
            case 'popup_pett':
                
                // Get data from the model
                $this->list_pett =& $model->getAllListPett();  
                //$this->pagination =& $this->get('PaginationTown');
                               
                $this->setLayout('popup_pett');
            break;
             case 'popup_loaihinh':
                
                // Get data from the model
                $this->list_pett =& $model->getAllListPett();  
                //$this->pagination =& $this->get('PaginationTown');
                               
                $this->setLayout('popup_loaihinh');
            break;
            case 'popup_club':
                
                // Get data from the model
                $this->list_club =& $model->getAllListClub();  
                //$this->pagination =& $this->get('PaginationTown');
                               
                $this->setLayout('popup_club');
            break;
            case 'popup_ocba':
                
                // Get data from the model
                $this->list_center =& $model->getAllListCenter();  
                                               
                $this->setLayout('popup_ocba');
            break;
             
            default:
                             
                //search
                $this->list['filter_typecc'] = &JRequest::getVar('filter_typecc');
                $this->list['filter_pref'] = &JRequest::getVar('filter_pref');
                $this->list['filter_namecc'] = &JRequest::getVar('filter_namecc');
                $this->list['filter_idcc'] = &JRequest::getVar('filter_idcc');
                $this->list['filter_year'] = &JRequest::getVar('filter_year');
                $this->list['filter_clubtype'] = &JRequest::getVar('filter_clubtype');
                $this->list['chb1'] = &JRequest::getVar('chb1');
                $this->list['chb2'] = &JRequest::getVar('chb2');
                $this->list['chb3'] = &JRequest::getVar('chb3');
                $this->list['chb4'] = &JRequest::getVar('chb4');
                $this->list['chb5'] = &JRequest::getVar('chb5');
                
                //Kiem tra co quyen Edit
                //if($aut->checkEditOwn()){
//                    $this->list['user_id'] = $aut->getUserID();
//                    $this->rows =& $model->getAll($this->list);
//                }else{
//                    $this->rows =& $model->getAll($this->list);
//                }
                
                // Get data from the model
                $this->rows =& $model->getAll($this->list);  
                $this->pagination =& $this->get('Pagination');
                //Get Master Facility Type
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                //Get list town
                $this->listpref =& $model->getAllPref();
                //Get list Club type
                $this->listclub =& $model->getAllClubType(); 
                
                
                $this->setLayout('a00600');
            
                JToolBarHelper::title( 'センター・クラブ情報管理','banners-tracks.png' );
       }
        
		parent::display($tpl);
       
	}
}




